package com.purchase.ml.service.email.user;

import com.purchase.ml.bean.req.mail.MailDto;
import com.purchase.ml.bean.req.mail.MailMessage;
import com.purchase.ml.consts.MailConstants;
import com.purchase.ml.entity.acc.SysUser;
import com.purchase.ml.mapper.sys.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author :zxm
 * @date :2021/3/23 16:59
 * @description :用户相关邮件
 **/
@Component
public class UserEmail {

    @Value("${mail.content.problemUrl:https://www.baidu.com/problemUrl}")
    private String problemUrl;
    @Value("${mail.content.generalEmail:123456@qq.com}")
    private String generalEmail;
    @Value("${mail.content.resetPwdAddress:https://www.baidu.com/resetPwdAddress}")
    private String resetPwdAddress;
    @Autowired
    private SysUserMapper sysUserMapper;

    public MailMessage getPwdReset(MailDto dto, String code) {
        // 通过邮箱获取到当前的用户
        SysUser user = sysUserMapper.selectByAccount(dto.getEmail());
        MailMessage mailMessage = new MailMessage();
        mailMessage.setEmail(dto.getEmail());
        mailMessage.setSubject("Password Reset");
        String content = "<font size='5' style=\"line-height: 200%;\">\n" +
                "<pre>\n" +
                "Hello "+ user.getAcc() +", \n" +
                "You have requested to reset the password at Evo Oil Dealership System. \n" +
                "Your reset code is "+ code +"\n" +
                "If you have problems, please copy and paste the below URL into your web browser. \n" +
                problemUrl +" \n" +
                "Need help? Contact us at "+ generalEmail +" \n" +
                "Thank you. \n" +
                "Best Regards, \n" +
                "Evo Oil Dealership System\n" +
                "</pre>\n" +
                "</font>";
        mailMessage.setText(content);
        mailMessage.setType(MailConstants.INFO_TYPE);
        return mailMessage;
    }
}
